$(function () {
    let layer = layui.layer;
    let form = layui.form;
    // ****************************************编辑用户

    let arr = location.href.split("=");
    let id = arr[1];

    $.ajax({
        url: '/admin/users/' + id,
        success: function (res) {
            if (res.status == 0) {
                form.val('editForm', res.data)
            }
        }
    })

    $('form').on('submit', function (e) {
        e.preventDefault();
        // 1.收集数据
        let data = $(this).serialize();
        data.Id = id;
        $.ajax({
            url: '/admin/users',
            type: "PUT",
            data: data,
            success: function (res) {
                layer.msg(res.message);
                let a = setTimeout(function () {
                    location.href = '/user/user.html'
                    clearTimeout(a);
                }, 800)
            }
        });
    })


})